<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>垂直水平居中</title>
    <style>
        .container1{
            width: 100%;
            height: 500px;
            /* padding:120px 0px; */
            background-color: pink;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .container1 .item{
            width:30%;
            height: 300px;
            background-color: blue;
        }

        .container2{
            width:  100%;
            height: 500px;
            /* padding:120px 0px; */
            background-color: #ccc; 
            position: relative;
        }

        .container2 .item{
            width:30%;
            height: 300px;
            background-color: blue;
            position:absolute;
            top:50%;
            left:50%;
            transform: translate(-50%,-50%);
        }
    </style>
</head>
<body>
    <div class="container1">
        <div class="item"></div>
    </div>

    <div class="container2">
        <div class="item"></div>
    </div>
</body>
</html>